<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        body {
            padding: 100px;
        }
        textarea {
            width: 200px;
            height: 100px;
            border: 1px solid pink;
            outline: none;
            resize: none;
        }
        ul {
            margin-top: 50px;
        }
        li {
            width: 300px;
            padding: 5px;
            background-color: rgb(245, 209, 243);
            color: red;
            font-size: 14px;
            margin: 15px 0;
        }
        li a {
            float: right;
            text-decoration: none;
            color: sandybrown;
        }
    </style>
</head>
<body>
    <textarea></textarea>
    <button>发布</button>
    <ul>
    </ul>
    <script>
        var ul = document.querySelector('ul');

        var btn = document.querySelector('button');
        var area = document.querySelector('textarea');
        btn.onclick = function () {
            if (area.value == '') {
                alert('请输入内容');
                return false;
            }else {
                // 删除节点在下面
                var li = document.createElement('li');
                li.innerHTML = area.value + '<a href="javascript:;">删除</a>';
                ul.insertBefore(li, ul.children[0]);

            }
            area.value = '';
            var as = document.querySelectorAll('a');
            for (var i = 0; i < as.length; i++) {
                    as[i].onclick = function() {
                        // node.removeChild(child); 删除的是 li 当前a所在的li  this.parentNode;
                        ul.removeChild(this.parentNode);
                    }
                }
        }

    </script>
</body>
</html>